package com.shawn.commons.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private static final SimpleDateFormat BIRTHDAY_FORMAT = new SimpleDateFormat(RC.GENERAL_DATE_FORMAT);

    /**
     * 计算年龄
     * @param birthday 生日
     * @return {@link Integer}
     */
    public static Integer countAge(String birthday) throws ParseException {
            long birthTime = BIRTHDAY_FORMAT.parse(birthday).getTime();
            return (int) ((new Date().getTime() - birthTime) / 365 / 24 / 3600 / 1000);
    }
}
